package com.cars.theadpool.service.impl;

import com.cars.theadpool.service.AsyncService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author: caoqianfan
 * @date: 2023/11/13 9:36
 */
@Slf4j
@Service
public class AsyncServiceImpl implements AsyncService {
    private static final Logger logger = LoggerFactory.getLogger(AsyncServiceImpl.class);

    @Async("asyncServiceExecutor")
//    @Resource(name = "asyncServiceExecutor")
    @Override
    public void executeAsync() {
        logger.info("start executeAsync");
        System.out.println("start executeAsync");
        System.out.println("当前运行的线程名称：" + Thread.currentThread().getName());
        logger.info("end executeAsync");
        System.out.println("end executeAsync");
    }

    /**
     * 可视化，可以打印线程池情况
     */
    @Override
    @Async("visibleTaskExecutor")
    public void visibleAsync() {
        log.info("== async start==");
        log.info("线程{}执行代码逻辑", Thread.currentThread().getName());
        log.info("== async end==");
    }

}